<?php
namespace Tbf\Bundle\PackageBundle\Type;
use Tbf\Bundle\PackageBundle\Annotation\Annotation;
use Tbf\Bundle\PackageBundle\Annotation\AnnotationCollection;

/**
 * a field on class(struct,database table)
 * used for package system
 */
class Field
{
    /** @var  string */
    protected $name;
    /**
     * 组管理
     * @var  \Tbf\Bundle\PackageBundle\Type\GroupManager
     */
    protected $group_manager;
    protected $default;
    /** @var  \Tbf\Bundle\PackageBundle\Type\TypeInterface */
    protected $type;
    /** @var  \Tbf\Bundle\PackageBundle\Annotation\AnnotationCollection */
    protected $annotation_list;
    /** @var  \Symfony\Component\Validator\Constraint */
    protected $constraint;

    protected $is_on_entity=true;

    public function __construct()
    {
        $this->annotation_list = new AnnotationCollection();
        $this->group_manager = new GroupManager();
    }
    /**
     * @param $name
     * @return Field
     */
    public static function create($name)
    {
        $obj = new static();
        $obj->setName($name);

        return $obj;
    }
    /**
     * @param  \Tbf\Bundle\PackageBundle\Annotation\Annotation $annotation
     * @return Field
     */
    public function addAnnotation(Annotation $annotation)
    {
        $this->annotation_list->addAnnotation($annotation);

        return $this;
    }

    /**
     * @param  \Tbf\Bundle\PackageBundle\Annotation\AnnotationCollection $annotation_list
     * @return Field
     */
    public function setAnnotationList($annotation_list)
    {
        $this->annotation_list = $annotation_list;

        return $this;
    }

    /**
     * @return \Tbf\Bundle\PackageBundle\Annotation\AnnotationCollection
     */
    public function getAnnotationList()
    {
        return $this->annotation_list;
    }

    /**
     * @param  \Symfony\Component\Validator\Constraint $constraint
     * @return Field
     */
    public function setConstraint($constraint)
    {
        $this->constraint = $constraint;

        return $this;
    }

    /**
     * @return \Symfony\Component\Validator\Constraint
     */
    public function getConstraint()
    {
        return $this->constraint;
    }

    /**
     * @param $default
     * @return Field
     */
    public function setDefault($default)
    {
        $this->default = $default;

        return $this;
    }

    public function getDefault()
    {
        return $this->default;
    }

    /**
     * @param \Tbf\Bundle\PackageBundle\Type\GroupManager $group_manager
     */
    public function setGroupManager($group_manager)
    {
        $this->group_manager = $group_manager;

        return $this;
    }

    /**
     * @return \Tbf\Bundle\PackageBundle\Type\GroupManager
     */
    public function getGroupManager()
    {
        return $this->group_manager;
    }

    /**
     * @param  string $name
     * @return Field
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param  \Tbf\Bundle\PackageBundle\Type\TypeInterface $type
     * @return Field
     */
    public function setType($type)
    {
        $this->type = $type;

        return $this;
    }

    /**
     * @return \Tbf\Bundle\PackageBundle\Type\TypeInterface
     */
    public function getType()
    {
        return $this->type;
    }
    public function NotOnEntity()
    {
        $this->is_on_entity = false;

        return $this;
    }
    public function isOnEntity()
    {
        return $this->is_on_entity;
    }
}
